if(window.plus){
    plusReady();
}else{
    document.addEventListener('plusready',plusReady,false);
}

function plusReady(){
    getConfSys();
    document.addEventListener('loadsysDate',getConfSys);
    loadnewsdata();
    getLineDate();
   // goHref();
}

//  全成本查询
function qcb(){
	//alert(1);
	// 这个是点击财务数据查询时候  会跳转到下面的选项卡
//  var main = plus.webview.currentWebview().parent();
//	mui.fire(main,'tabClick',{tabId:'cwcx'});
mui.openWindow({
		url:"/work/report_form/query_qcbcx.html",
//		id:"gzdtdetail",
//		extras:{ID:ID},
//		waiting:{autoShow:false}
	});
}


//  操作成本查询
function czcb() {
	mui.openWindow({
		url:"/work/report_form/query_xjczcbb.html",
	});
}

// 运销费用查询
function yxfy() {
	mui.openWindow({
		url:"/work/report_form/query_yxfycx.html",
	});
}

// 管理费用查询
function glfy() {
	mui.openWindow({
		url:"/work/report_form/query_glfcx.html",
	})
}



// 财务数据四个小圈跳转
/*function goHref() {
	var oP1 = $("#p1");
	oP1.click(function(){
		alert("llii");
	});
}*/

//加载页面信息，system
function getConfSys(){
	document.getElementsByTagName('body')[0].scrollTop = 0;
    //请求后台
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/mobile/getConfSys',{
	   data: {token:token},
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data) {
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
              var sys = data.message;
              var table = document.body.querySelector('.mui-table-view');
              table.innerHTML = "";
              for(var i=0;i<sys.length;i++){
              	 var sy=sys[i];
              	 var li = document.createElement('li');
              	 if(sy.xtlx==0){
              	 	 li.className = 'mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3 pan_ul_li';
              	     li.innerHTML ='<a href="javascript:void(0)" onclick="locallist(\''+sy.xtbh+'\')"><span class="mui-icon"><img src="'+sy.xttp+'"/ style="width: 50px;height: 50px;"><span class="mui-badge mui-badge-warning" style="margin-left:-15px;">'+sy.dbnum+'</span></span><div class="mui-media-body pan_system_label">'+sy.xtmc+'</div></a>';
              	 }else{
              	 	 li.className = 'mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3 pan_ul_li';
              	 	 li.innerHTML ='<a href="javascript:void(0)" onclick="locallist(\''+sy.xtbh+'\')"><span class="mui-icon"><img src="'+sy.xttp+'"/ style="width: 50px;height: 50px;"></span><div class="mui-media-body pan_system_label">'+sy.xtmc+'</div></a>';
              	 }
              	 table.appendChild(li);
              }
		   }else{
		   	    mui.toast(data. message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! system.js1');
	    }
		});
	}
}
//首页代办点击事件
function systemlist(param){
   //获得主页面的webview
   var main = plus.webview.currentWebview().parent();
   //触发主页面的gohome事件tabId:'toDoTab',s
   mui.fire(main,'tabClick',{tabId:'toDoTab','xtbh':param});
}
//首页点击原油价格图事件
function locallist(xtbh){
	var listview;
	if(xtbh=='xt02'){
	   listview=mui.openWindow({url:"work/oilPrice/oilPriceLine.html",id:"oilPriceLine",waiting:{autoShow:false}});
	}else if(xtbh=='xt03'){
	   listview=mui.openWindow({url:"work/dataQuery/dataQuery.html",id:"dataQuery",waiting:{autoShow:false}});
	}else if(xtbh=='xt01'){
	   listview=mui.openWindow({url:"zjxtyw.html",id:"zjxt",extras:{xtbh:xtbh},waiting:{autoShow:false}});
	}else if(xtbh=='xt04'){
	   listview=mui.openWindow({url:"zcyw/zcxtyw.html",id:"zcxt",extras:{xtbh:xtbh},waiting:{autoShow:false}});
	}
}
function getLineDate(){
	
	var data1=new Array();
	var data2=new Array();
	var data3=new Array();
	// 获取当天的新闻
    mui.ajax(baseServerAdrr+'/news/getYdysAndZxChart',{
  	  dataType:'json',//服务器返回json格式数据
      type:'post',//HTTP请求类型
      timeout:30000,//超时时间设置为10秒；
      success:function(data){
          for(var i=0;i<data.length;i++){
          		var dataa=data[i];
          		data1.push(dataa.f_ysqj);
          		data2.push(dataa.f_ydys);
          		data3.push(dataa.f_ydzx);
          }
          drawline(data1,data2,data3);
       },
      error:function(xhr,type,errorThrown){
           //异常处理；
         //mui.toast('服务器异常登录失败! system.js2');
       }
    });
}

function drawline(data1,data2,data3){
	var linewidth=plus.display.resolutionWidth;
	
	var data = [
	            {name : '预算金额',value:data2,color:'#FF797B'},
				{name : '执行金额',value:data3,color:'#FFBE39'}
			   ];
    var labels=data1;
	var chart = new iChart.ColumnMulti2D({
			render : 'canvasDiv',
			data: data,
			shadow: false,
			label : {
				fontsize:11,
				textAlign:'right',
				textBaseline:'middle',
				rotate:-25,
				color : '#666666'
			},
			labels:labels,
			title : {
    		    text: '资金月度预算实际对比分析',
    		    font: '微软雅黑',
    		    fontsize: 16,
    		    color: '#000',
    		    padding:-10
    	    },
			subtitle : '',
			footnote : ' ',
			width : linewidth,
			height : linewidth*2/3,
			background_color : '#fff',
			turn_off_touchmove:true,
			border : {enable : false},
			sub_option: {
    		   smooth: true,
    		   label: false,
    		   hollow: false,
    		   hollow_inside: false,
    		   point_size: 1
    	    },
			legend:{
				align:"center",
				valign:"top",
				enable:true,
				column:2,
				offsety:-25,
				background_color : null,
				border : {enable : false}
			},
			coordinate:{
				background_color : '#fff',
				grid_color: '#AFAAAA',
				axis: {
    			   color: '#252525',
    			   width: [0, 0, 1, 1]
    		    },
				scale:[{
					position:'left',
					start_scale:0,
					end_scale:140,
				    scale_space:20
				}],
				width:linewidth-60,
				height:linewidth*2/3
			}
		});
		  //利用自定义组件构造左侧说明文本
    chart.plugin(new iChart.Custom({
    	drawFn: function() {
    		//计算位置
    		var coo = chart.getCoordinate(),
    			x = coo.get('originx'),
    			y = coo.get('originy'),
    			w = coo.width,
    			h = coo.height;
    		//在左上侧的位置，渲染一个单位的文字
    		chart.target.textAlign('start')
    			.textBaseline('bottom')
    			.textFont('11px 微软雅黑')
    			.fillText('(亿元)', x - 20, y -10, false, '#747070')
    			.textBaseline('top');    
    	}
    }));
	chart.draw();							
}

function loadnewsdata(){
    mui.ajax(baseServerAdrr+'/news/getWorkNews',{
  	  dataType:'json',//服务器返回json格式数据
  	  data: {pagenum:"1",syf:"true"},
      type:'post',//HTTP请求类型
      timeout:30000,//超时时间设置为10秒；
      success:function(data){
          var innerhtml="";
          if(data.code=='success'){
                 var lists = data.data;
                 for (var i=0;i<lists.length;i++) {
                 	var list=lists[i];
                 	if(list.CHECKER!=null&&list.CHECKER!=""){
                 		innerhtml+='<li class="mui-table-view-cell mui-media">';
                 		innerhtml+='  <a href="javascript:void(0);" onclick=\'detail_see("'+list.ID+'")\'>';
                 		innerhtml+='   <img class="mui-media-object mui-pull-right news-image" src="'+baseServerAdrr.replace("espsl5","")+list.CHECKER+'">';
                 		innerhtml+='   <div class="mui-media-body">';
                 		innerhtml+='      <p class="mui-ellipsis news-content">'+list.TITLE+'</p>';
                 		innerhtml+='   </div>';
                 		innerhtml+='   <div class="news-small">';
                 		innerhtml+='      <span>发布时间：'+list.DATEPUBLISHED+'</span>&nbsp;&nbsp;<span>访问量：'+list.PRINTNUM+'</span>';
                 		innerhtml+='   </div></a></li>';
                 	}else{
                 		innerhtml+='<li class="mui-table-view-cell mui-media">';
                 		innerhtml+='  <a href="javascript:void(0);" onclick=\'detail_see("'+list.ID+'")\'>';
                 		innerhtml+='   <div class="mui-media-body">';
                 		innerhtml+='      <p class="mui-ellipsis news-content">'+list.TITLE+'</p>';
                 		innerhtml+='   </div>';
                 		innerhtml+='   <div class="news-small">';
                 		innerhtml+='      <span>发布时间：'+list.DATEPUBLISHED+'</span>&nbsp;&nbsp;<span>访问量：'+list.PRINTNUM+'</span>';
                 		innerhtml+='   </div></a></li>';
                 	}
                 }
                 $('.news-table').html(innerhtml);                 
          }else{
  	           mui.toast(data.message);
          }
       },
      error:function(xhr,type,errorThrown){
           //异常处理；
          //mui.toast('服务器异常登录失败!  system.js3');
       }
   });
}

function detail_see(ID){
	mui.openWindow({
		url:"/work/xwmk/gzdtdetail.html",
		id:"gzdtdetail",
		extras:{ID:ID},
		waiting:{autoShow:false}
	});
}


